/**
 * 闪灯鸣笛
 */
function carLocating(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 车锁开关
 */
function carLock(services, sid, data) {
  const currentState = data && data.currentState
  if (currentState) {
    // 根据传入的值修改5个sid的值
    // doorRow1Left、doorRow1Right、doorRow2Left、doorRow2Right、carLock
    for (const service of services) {
      const { sid: sSid, data: sData } = service
      if (sSid === 'carLock') {
        sData['currentState'] = currentState
      } else if (['doorRow1Left', 'doorRow1Right', 'doorRow2Left', 'doorRow2Right'].indexOf(sSid) >= 0) {
        sData['doorLock'] = currentState
      }
    }
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 第一块天窗
 */
function windowRoofTop1(services, sid, data) {
  const windowMove = data && data.windowMove
  for (const service of services) {
    const { sid: sSid, data: sData } = service
    if (sSid === 'windowRoofTop1') {
      sData['windowPos'] = windowMove
      sData['windowMove'] = windowMove
    }
  }
  return { code: 0, services }
}

/**
 * 第一排左侧座椅
 */
function seatRow1Left(services, sid, data) {
  const hvacSeatTemperature = data && data.hvacSeatTemperature
  const hvacSeatVentilation = data && data.hvacSeatVentilation
  for (const service of services) {
    const { sid: sSid, data: sData } = service
    if (sSid === 'seatRow1Left') {
      sData['hvacSeatTemperature'] = hvacSeatTemperature
      sData['hvacSeatVentilation'] = hvacSeatVentilation
    }
  }
  return { code: 0, services }
}

/**
 * 第一排右侧座椅
 */
function seatRow1Right(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 第二排左侧座椅
 */
function seatRow2Left(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 第二排右侧座椅
 */
function seatRow2Right(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 整车空调和通风
 */
function hvac(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 右侧区域空调和通风
 */
function hvacRight(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 左侧区域空调和通风
 */
function hvacLeft(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 前挡风玻璃
 */
function windowFrontWindshield(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 后挡风玻璃
 */
function windowRearWindshield(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

/**
 * 整车窗户
 */
function allWindows(services, sid, data) {
  const trigger = data && data.trigger
  if (trigger) {
    // 值为true时才执行成功
    return { code: 0, services }
  }
  // TODO: 这里的错误码需要支持定制
  return { code: 10001, services }
}

module.exports = {
  carLocating,
  carLock,
  allWindows,
  hvac,
  hvacLeft,
  hvacRight,
  seatRow1Left,
  seatRow1Right,
  seatRow2Left,
  seatRow2Right,
  windowFrontWindshield,
  windowRearWindshield,
  windowRoofTop1
}
